package com.dragon.modules.yuegou.client.ali.service.impl;

import com.dragon.modules.yuegou.client.ali.client.CheckBankNoClient;
import com.dragon.modules.yuegou.client.ali.response.CardDetailResponse;
import com.dragon.modules.yuegou.client.ali.service.CheckBankNoService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

public class CheckBankNoServiceImpl implements CheckBankNoService {

    @Autowired
    private CheckBankNoClient checkBankNoClient;

    private Map<String,String> map;
    public CheckBankNoServiceImpl(){
        map = new HashMap<>();
        map.put("ICBC", "工商银行");
        map.put("ABC", "农业银行");
        map.put("BOC", "中国银行");
        map.put("CCB", "建设银行");
        map.put("CMB", "招商银行");
        map.put("PSBC", "邮储银行");
        map.put("COMM", "交通银行");
        map.put("SPDB", "浦发银行");
        map.put("CMBC", "民生银行");
        map.put("CIB", "兴业银行");
        map.put("SPABANK", "平安银行");
        map.put("CITIC", "中信银行");
        map.put("HXBANK", "华夏银行");
        map.put("GDB", "广发银行");
        map.put("CEB", "光大银行");
        map.put("BJBANK", "北京银行");
        map.put("NBBANK", "宁波银行");
        map.put("SHBANK", "上海银行");
    }

    @Override
    public Boolean checkCardDetail(String cardNo, String backName) {
        CardDetailResponse cardDetailResponse = checkBankNoClient.checkCardDetail(cardNo);
        if (cardDetailResponse.getValidated() && "ok".equals(cardDetailResponse.getStat()))  {
            String bank = cardDetailResponse.getBank();
            return map.get(bank).equals(backName);
        }
        return false;
    }
}
